use winit::{
    event::*,
    event_loop::EventLoop,
    window::WindowBuilder,
};
use wgpu_canvas::{Pixmap, LoadOp, Color};


pub async fn run() {
    env_logger::init();
    let event_loop = EventLoop::new().unwrap();
    let window = WindowBuilder::new().build(&event_loop).unwrap();
    let id = window.id();
    let size = window.inner_size();
    let mut canvas = Pixmap::new_for_target(&window, size.width, size.height).await;
    canvas.load_op = LoadOp::Clear(Color { r: 0.004, g: 0.0005, b: 0.004, a: 1.0 });

    event_loop.run(move |event, _| match event {

        Event::WindowEvent {
            ref event,
            window_id,
        } if window_id == id => match event {
            WindowEvent::RedrawRequested => {
                canvas.render()
            },
            WindowEvent::Resized(size) => {
                canvas.resize(size.width, size.height)
            }
            _ => {}
        },
        _ => {}
    }).unwrap();
}
